package com.info.zhiduoduo.weixin.controller;

import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.repository.dto.invoice.InvoiceBriefDto;
import com.info.zhiduoduo.repository.dto.invoice.InvoiceDetailDto;
import com.info.zhiduoduo.weixin.formbean.invoice.InvoiceFormBean;
import com.info.zhiduoduo.weixin.formbean.invoice.OfflinePayReceiptFormBean;
import com.info.zhiduoduo.weixin.formbean.invoice.QueryInvoiceFormBean;
import com.info.zhiduoduo.weixin.service.InvoiceService;
import com.info.zhiduoduo.weixin.service.ProjectService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/invoice")
public class InvoiceController extends CommonController {

	@Autowired
	InvoiceService invoiceService;
	@Autowired
	ProjectService projectService;

	/**
	 * 申请支票
	 *
	 */
	@PostMapping("/v1/applyInvoice")
	public SmartResult applyInvoice(@RequestBody BaseSimpleFormBean<InvoiceFormBean> baseSimpleFormBean){
		return invoiceService.saveInvoice(baseSimpleFormBean);
	}

	/**
	 * 创客 发票列表
	 *
	 */
	@PostMapping("/v1/invoiceForUser")
	public SmartResult<InvoiceBriefDto> invoiceForUser(@RequestBody BaseSimpleFormBean<QueryInvoiceFormBean> baseSimpleFormBean){
		return invoiceService.queryInvoiceForUser(baseSimpleFormBean);
	}

	/**
	 * 企业 发票列表
	 *
	 */
	@PostMapping("/v1/invoiceForCompany")
	public SmartResult<InvoiceBriefDto> invoiceForCompany(@RequestBody BaseSimpleFormBean<QueryInvoiceFormBean> baseSimpleFormBean){
		return invoiceService.queryInvoiceForCompany(baseSimpleFormBean);
	}

	@ApiOperation("保存线下项目转账凭证")
	@PostMapping("/saveOfflinePayReceipt")
	public SmartResult saveOfflinePayReceipt(@RequestBody BaseSimpleFormBean<OfflinePayReceiptFormBean> formBean) {
		return invoiceService.saveOfflinePayReceipt(formBean);
	}

	@ApiOperation(value = "发票详情", notes = "reqdata:invoiceid 发票id")
	@PostMapping("/detail")
	public SmartResult<InvoiceDetailDto> getDetail(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return invoiceService.getDetail(formBean);
	}

	@ApiOperation("支付线下项目开票费用")
	@PostMapping("/payInvoiceServiceCharge")
	public SmartResult payInvoiceServiceCharge(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return invoiceService.payInvoiceServiceCharge(formBean);
	}

	@GetMapping("downloadInvoice")
	public void downloadInvoice(HttpServletResponse response) {

		invoiceService.downloadInvoice(response);
	}
}
